import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';

@Injectable()
export class OrderService {
    constructor(@InjectModel('Order') private readonly orderModel, @InjectModel('OrderItem') private readonly orderItemModel) {}
    async find(where = {}, sort = { sort: 1, createdTime: -1 }, fields = null) {
        return await this.orderModel.find(where, fields).sort(sort);
    }
    async findOrderItem(where = {}, sort = { sort: 1, createdTime: -1 }, fields = null) {
        return await this.orderItemModel.find(where, fields).sort(sort);
    }
    async create(orderInfo) {
        return await this.orderModel.create(orderInfo);
    }
    async createOrderItem(orderItemInfo) {
        return await this.orderItemModel.create(orderItemInfo);
    }
    async update(orderInfo) {
        return await this.orderModel.updateOne({ _id: orderInfo._id }, orderInfo);
    }
    async delete(orderInfo) {
        return await this.orderModel.deleteOne(orderInfo);
    }
    getModel() {
        return this.orderModel;
    }
}
